package com.ruoyi.folder.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.folder.domain.Depart;
import com.ruoyi.folder.service.IDepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 系统部门管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/depart")
public class DepartController extends BaseController
{
    @Autowired
    private IDepartService departService;

    /**
     * 查询系统部门管理列表
     */
    @RequiresPermissions("depart:depart:list")
    @GetMapping("/list")
    public TableDataInfo list(Depart depart)
    {
        startPage();
        List<Depart> list = departService.selectDepartList(depart);
        return getDataTable(list);
    }

    /**
     * 导出系统部门管理列表
     */
    @RequiresPermissions("depart:depart:export")
    @Log(title = "系统部门管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Depart depart)
    {
        List<Depart> list = departService.selectDepartList(depart);
        ExcelUtil<Depart> util = new ExcelUtil<Depart>(Depart.class);
        util.exportExcel(response, list, "系统部门管理数据");
    }

    /**
     * 获取系统部门管理详细信息
     */
    @RequiresPermissions("depart:depart:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(departService.selectDepartById(id));
    }

    /**
     * 新增系统部门管理
     */
    @RequiresPermissions("depart:depart:add")
    @Log(title = "系统部门管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Depart depart)
    {
        return toAjax(departService.insertDepart(depart));
    }

    /**
     * 修改系统部门管理
     */
    @RequiresPermissions("depart:depart:edit")
    @Log(title = "系统部门管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Depart depart)
    {
        return toAjax(departService.updateDepart(depart));
    }

    /**
     * 删除系统部门管理
     */
    @RequiresPermissions("depart:depart:remove")
    @Log(title = "系统部门管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(departService.deleteDepartByIds(ids));
    }
}
